package org.adorsys.aderp.orga.domain;

import javax.persistence.Column;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.StringUtils;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaEntity
public class OrgaAddress {

    @NotNull
    @Column(name = "addressKeyBk", unique = true)
    private String addressKey;

    private String addressLineOne;

    private String addressLineTwo;

    private String addressQuater;

    private String addressZip;

    private String addressCityName;

    private String addressDistrictName;

    private String addressRegionName;

    private String addressCountry;

    private String phoneNumber;

    private String geoCoordLongitude;

    private String geoCoordLatitude;

    private String description;

    @NotNull
    @ManyToOne
    private Country country;

    @ManyToOne
    private Region addressRegion;

    @ManyToOne
    private District addressDistrict;

    @ManyToOne
    private City addressCity;

    private String recordOwner;

    public String printAddress(){
        return new StringBuilder().append(addressLineOne)
        		.append(", ").append(addressLineTwo)
        		.append(", ").append(StringUtils.isBlank(addressZip)?addressQuater:addressZip)
        		.append(", ").append(addressCity==null?addressCityName:addressCity.getTitle())
        		.append(", ").append(addressDistrict==null?addressDistrictName:addressDistrict.getTitle())
        		.append(", ").append(addressRegion==null?addressRegionName:addressRegion.getTitle())
        		.append(", ").append(country==null?addressCountry:country.getTitle())
        		.toString();    	
    }
}
